package com.aaa.rabbitmq.seven;

import com.aaa.rabbitmq.one.util.RabbitMQUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * 主题交换机 主题模式   最灵活
 *
 */
public class EmitLogTopic {
    //交换机的名称
    public static final String EXCHANGE_NAME = "topic_logs";

    public static void main(String[] args) throws Exception{
        Channel channel = RabbitMQUtil.getChannel();

        /**
         * Q1 绑定交换机 topic_logs  RoutingKey为 *.orange.*
         * Q1 绑定交换机 topic_logs两次  RoutingKey为 *.*.rabbit 和 lazy.#
         */
        Map<String, String> map = new HashMap<>();
        map.put("quick.orange.rabbit","Q1和Q2");
        map.put("lazy.orange.elephant","Q1和Q2");
        map.put("quick.orange.fox","Q1");
        map.put("lazy.brown.fox","Q2");
        map.put("lazy.pink.rabbit","虽然满足两个绑定但是只被Q2接收一次");
        map.put("quick.brown.fox","不匹配任何绑定会被丢弃");
        map.put("quick.orange.male.rabbit","四个单词没不匹配任何绑定会被丢弃");
        map.put("lazy.orange.male.rabbit","是四个单词 匹配Q2");

        for (Map.Entry<String, String> stringEntry : map.entrySet()) {
            String routingKey = stringEntry.getKey();
            String msg = stringEntry.getValue();
            //用信道 发消息
            channel.basicPublish(EXCHANGE_NAME,routingKey,null,msg.getBytes(StandardCharsets.UTF_8));
            System.out.println("生产者发送消息完成: "+msg);
        }


    }
}
